<template>
  <div>
    <Button
      v-if="type == 0"
      @click="OnSendCode"
      circle="0"
      class="btn-submit"
      :class="{'disable': isDisabled}"
      :disabled="isDisabled">{{ButtonName}}</Button>
    <Button
      v-else-if="type == 1"
      @click="OnSendCode"
      circle="0"
       class="btn-submit"
      :class="{'disable': isDisabled}"
      :disabled="isDisabled"
    >{{ ButtonName}}</Button>
  </div>
</template>
<script>
export default {
  props: {
    type: {
      type: Number,
      default: 0
    }
    // isDisabled: {
    //   type: Boolean,
    //   default: false
    // },
    // ButtonName: {
    //   type: String,
    //   default: '发送短信'
    // },
    // time: {
    //   type: Number,
    //   default: 60
    // }
  },
  data() {
    return {
      isDisabled: false,
      ButtonName: '发送短信',
      time: 60,
      interval: ''
    }
  },
  methods: {
    OnSendCode() {
      this.$emit('complete')
    },
    reset() {
      this.interval && window.clearInterval(this.interval)
      this.isDisabled = false
      this.ButtonName = '发送短信'
      this.time = 60
    },
    sendMsg() {
      let me = this;
      this.interval && window.clearInterval(this.interval)
      // me[sendDisable]= false
      // me[sendName] = '发送短信'
      // me[paramTime] = 60
      me['isDisabled'] = true;
      this.interval = window.setInterval(function() {
        me['ButtonName'] = "（" + me['time'] + "秒）"
        --me['time']
        if (me['time'] < 0) {
          me['ButtonName'] = "重新发送"
          me['time'] = 60
          me['isDisabled'] = false
          window.clearInterval(me.interval)
        }
      }, 1000)
    }
  }
}
</script>